type requestMethod='OPTIONS' | 'GET' | 'HEAD' | 'POST' | 'PUT' | 'DELETE' | 'TRACE' | 'CONNECT';
interface IParam {
	url:string;
	method?:requestMethod;
	data?:any
}

  interface RequestSuccessCallbackResult {
    /**
     * 开发者服务器返回的数据
     */
    data: any;
    /**
     * 开发者服务器返回的 HTTP 状态码
     */
    statusCode: number;
    /**
     * 开发者服务器返回的 HTTP Response Header
     */
    header: any;
    /**
     * 开发者服务器返回的 cookies，格式为字符串数组
     */
    cookies: string[];
  }
export interface IBaseResponse extends RequestSuccessCallbackResult {
	
	data:{
		"errCode": 0| 400,
		"errMsg":string,
		"data": any,
		"author": string,
		"timeCost":number
	}
	    
	
}

const BaseUrl = "https://tea.qingnian8.com/api/bizhi"
export  function request(param:IParam):Promise<any>{
	let {
		url,method='GET',data={}
	} = param
	return new Promise((resolve,reject)=>{
		uni.request({
			url:BaseUrl+url,
			data,
			method,
			header:{
				"access-key":"simakazai"
			},
			success: (res:IBaseResponse) => {
				if(res.data.errCode===0){
					resolve(res.data.data)
				}else if(res.data.errCode===400){
					uni.showModal({
						title:"错误提示",
						content:res.data.errMsg,
						showCancel:true
					})
				}else{
					uni.showToast({
						title:res.data.errMsg,
						icon:"none"
					})
				}
			},
			fail: (err) => {
				reject(err)
			}
		})
	})


	
}